package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Social;

public class SocialDAOImpl extends BaseHibernateDAOImpl<Social> implements SocialDAO {

	public Social getSocialBySocialID(String socialID) {
		Social social;
		try {
			social = (Social) getSession().get(Social.class, socialID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return social;
	}

	@SuppressWarnings("unchecked")
	public List<Social> getAllSocialOfMonth(String year, String month) {
		List<Social> socials;
		try {
			Query query = getSession().getNamedQuery("AllSocialOfMonthQuery");
			query.setString("year", year);
			query.setString("month", month);
			socials = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return socials;
	}

	@SuppressWarnings("unchecked")
	public List<Social> getAllSocialOfMonthByPage(int currentPage, int lineSize, String year, String month) {
		List<Social> Socials;
		try {
			Query query = getSession().getNamedQuery("AllSocialOfMonthByPageQuery");
			query.setString("year", year);
			query.setString("month", month);
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			Socials = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return Socials;
	}

}
